import axios from '@/utils/axios'
import moment from "moment";
import request from '../service/request';
import { ElMessage } from 'element-plus';
import store from '@/store/index';


export function getEmpList(params) {
  return axios({
    url: '/auth/user/list',
    method: 'post',
    data: params
  })
}

/**
 * 获取用户列表接口
 * @returns Object
 */
export const getUserList = async (searchForm) => {
  const data = await request.get('/auth/employee/list', {
    params: searchForm,
  });
  return data.data;
};

/**
 * 验证工号是否重复
 * @returns Object
 */
export const validate = async (searchForm) => {
  const data = await request.get('/auth/employee/validate', {
    params: searchForm,
  });
  return data;
};

/**
 * 新增用户
 * @returns null
 */
export const addUser = async (employee) => {
  await request.post('/auth/employee/add', employee);
  ElMessage.success('新增用户成功');
};

/**
 * 获取用户信息
 * @returns Object
 */
export const getUserInfo = async (userId) => {
  const data = await request.get(`/auth/employee/info/${userId}`);
  return data.data;
};

/**
 * 修改用户
 * @returns null
 */
export const updateUser = async (commitForm) => {
  const data = await request.put('/auth/employee/update', commitForm);
  if (data.code !== 0) ElMessage.success('修改用户成功');
};

/**
 * 删除用户
 * @returns null
 */
export const deleteUser = async (userIds) => {
  const data = await request.delete(`/auth/employee/delete/${userIds}`);
  if (data.code !== 0) ElMessage.success('删除用户成功');
};
/**
 * 得到该部门下的所有岗位
 * @returns Object
 */
export const getPost = async (id = 1) => {
  const data = await request.get(`/auth/dept/positions/${id}`);
  return data.data;
};
/**
 * 得到地区列表
 * @returns Object
 */
export const getRegion = async () => {
  const data = await request.get('/auth/employee/getRegion');
  return data.data;
};

/**
 * 验证旧密码是否正确
 * @returns Object
 */
export const validateOldPwd = async (old) => {
  const empId = store.getters.userInfo.id
  const data = await request.get('/auth/employee/validateOldPwd', {
    params: {
      oldPwd: old,
      id: empId
    },
  });
  return data;
};

/**
 * 修改密码
 * @returns Object
 */
export const changePwd = async (empId, pwd) => {
  const data = await request.get('/auth/employee/changePwd', {
    params: {
      newPwd: pwd,
      id: empId
    },
  });
  return data;
};

/**
 * 获取个人信息
 * @returns Object
 */
export const getEmpInfo = async (empId) => {
  const data = await request.get(`/auth/employee/empInfo/${empId}`);
  return data.data;
};
